﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using prototype123.models;
using prototype123.controllers;

namespace prototype123
{
    public partial class end_term : Form
    {
        public end_term()
        {
            InitializeComponent();
        }

        // Closes the Form. Term is not ended.
        private void button2_Click(object sender, EventArgs e) // cancel
        {
            // Cancel the end term by

            // Closing the end_term form User Interface

            this.Close(); // closes the end_term form
        }

        // Ends the term if successful.
        // Otherwise, an error message is displayed
        private void button1_Click(object sender, EventArgs e) // end term
        {
            // verify that txtInstrucDays and Date are not empty

            // Check to see if the assignments and grades are filled in correctly

            // tm = termController.EndTerm(currentTerm)

            // Keep user from further editing term by disabling some UI elements in main_form.cs

            this.Close(); // closes the end_term form
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {

        }

        private void btnEndTerm_Click(object sender, EventArgs e)
        {
            int days;
            try { days = Convert.ToInt32(txtInstructDays.Text); }
            catch { MessageBox.Show("Instructional days must be a valid number"); return; }
            DateTime date = dtpEndDate.Value;
            if (date > DateTime.Now)
            {
                MessageBox.Show("End Date must be today or earlier."); return;
            }

            EndTermController endctrl = new EndTermController();
            bool isTermEnded = endctrl.EndTerm(date);
            if (isTermEnded)
            {
                MessageBox.Show("The term has been ended for" +
                SystemController.Instance.CurrentStudent.FirstName + " " +
                SystemController.Instance.CurrentStudent.LastName);
            }
            else { MessageBox.Show("Term ending failed."); }
        }

    }
}
